package com.primeton.wh.mcenter.impl.message.service.impl;

import com.primeton.wh.mcenter.api.response.CodeMsg;
import com.primeton.wh.mcenter.api.response.Result;
import com.primeton.wh.mcenter.impl.client.CapUserClient;
import com.primeton.wh.mcenter.impl.message.param.EmployeeDetailVO;
import com.primeton.wh.mcenter.impl.message.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: YunTao.Li
 * @create: 2020-04-03 13:15
 * @description:
 **/
@Service
public class LoginServiceImpl implements ILoginService {

    @Autowired
    private CapUserClient capUserClient;

    /**
     * 根据coframe的token解码后的username获得员工信息
     *
     * @param confUser :
     * @return : java.util.Map<java.lang.String,java.lang.String>
     * @author : YunTao.Li
     * @date : 2020/4/3 2020/4/3
     */
    @Override
    public Map<String, String> getEmpInfoByCofUser(String confUser) throws Throwable {
        Map<String, String> empMap = new HashMap<String, String>();
        try {
            Result<EmployeeDetailVO> empDetailResult = capUserClient.getEmpDetail(null, confUser);
            EmployeeDetailVO empVO = empDetailResult.getData();
            if (empDetailResult.getCode() == CodeMsg.Success.getCode()) {
                String empCode = empVO.getEmpCode();
                String empName = empVO.getEmpName();
                String appId = empVO.getAppId();
                String orgId = empVO.getOrgId();
                String orgCode = empVO.getOrgName();


                empMap.put("empCode", empCode);
                empMap.put("empName", empName);
                empMap.put("appId", appId);
                empMap.put("orgId", orgId);
                empMap.put("orgCode", orgCode);
            }

        } catch (Throwable e) {
            e.printStackTrace();
        }

        return empMap;
    }
}
